package com.soap.controller;



import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.soap.entity.dto.UserDto;
import com.soap.entity.po.User;
import com.soap.entity.query.UserQuery;
import com.soap.entity.vo.UserLoginVo;
import com.soap.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 *
 * 用户模块
 *
 * @author ZhangPY
 * @since 2020-05-28
 */
@RestController
@Api(value = "用户模块" , tags = "用户模块")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @ApiOperation(value = "通过手机号添加user")
    @RequestMapping(value = "/addUserByPhone" , method = RequestMethod.POST)
    public String addUserByPhone(UserDto userDto) {
        return userService.addUserByPhone(userDto);
    }

    @ApiOperation(value = "更新用户")
    @RequestMapping(value = "/updateUser" , method = RequestMethod.POST)
    public String updateUser(User userDto) {
        return userService.updateUser(userDto);
    }


    @ApiOperation(value = "登录")
    @RequestMapping(value = "/accredit" , method = RequestMethod.POST)
    public String accredit(UserLoginVo userLoginVo) {
        return userService.accredit(userLoginVo);
    }

    /**
     * 微信扫码登陆后微信回调
     * @return
     */
    @ApiOperation(value = "微信扫码登陆后微信回调")
    @RequestMapping(value = "/WxCallback")
    public String WxCallback(String code) {
        return userService.WxCallback(code);
    }


    @ApiOperation(value = "校验token")
    @RequestMapping(value = "/checkToken" , method = RequestMethod.GET)
    public String checkToken(HttpServletRequest request) {
        String token = request.getHeader("token");
        return userService.checkToken(token);
    }

    @ApiOperation(value = "分页查询User")
    @RequestMapping(value = "/getUserListByPage" , method = RequestMethod.POST)
    public String getUserListByPage(HttpServletRequest request, UserQuery userQuery) {
        return userService.getUserListByPage(userQuery);
    }

    @ApiOperation(value = "修改用户状态")
    @RequestMapping(value = "/lockOrUnLockUser" , method = RequestMethod.POST)
    public String lockOrUnLockUser(HttpServletRequest request, Long userId, Boolean lockedState) {
        return userService.lockOrUnLockUser(userId, lockedState);
    }

    @ApiOperation(value = "通过id查询用户")
    @RequestMapping(value = "/getUserById" , method = RequestMethod.POST)
    public String getUserById(HttpServletRequest request, Long userId) {
        return userService.getUserById(userId);
    }

}
